﻿using System.IO;
using System.Reflection;

namespace FaceDotnet
{
    /// <summary>
    /// 资源文件
    /// </summary>
    static class ResourceFile
    {
        const string outdir = "resource";
        private static readonly Assembly assembly = typeof(ResourceFile).Assembly;

        /// <summary>
        /// 导出资源文件
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <returns></returns>
        public static string Export(string fileName)
        {
            var filePath = Path.Combine(outdir, fileName);
            if (File.Exists(filePath) == false)
            {
                var assemblyName = assembly.GetName().Name;
                var resourceName = $"{assemblyName}.{fileName}";

                Directory.CreateDirectory(outdir);
                using var stream = assembly.GetManifestResourceStream(resourceName);
                using var fileStream = new FileStream(filePath, FileMode.OpenOrCreate);
                stream.CopyTo(fileStream);
            }
            return Path.GetFullPath(filePath);
        }
    }
}
